import csv

# 替换为你的 CSV 文件路径
csv_file_path = 'music_rankings.csv'

# 生成的 SQL 语句将被保存到这个文件
output_sql_file_path = 'insert_statements.sql'

# 读取 CSV 文件并生成 SQL 语句
with open(csv_file_path, mode='r', encoding='utf-8') as file:
    reader = csv.reader(file)
    next(reader)  # 跳过标题行
    index = 1
    insert_statements = []
    for row in reader:
        song_id, rank, average_rating = row
        # 假设 song_id 是 MusicDetails 表中的主键
        sql = f"INSERT INTO `music_hotmusic` (`id`, `music_id`, `rank`, `average_rating`) \
        VALUES ({index},{song_id}, {rank}, {average_rating});"
        insert_statements.append(sql)
        index += 1

# 将 SQL 语句写入文件
with open(output_sql_file_path, mode='w', encoding='utf-8') as file:
    for statement in insert_statements:
        file.write(statement + "\n")

print(f"SQL 语句已生成并保存到 {output_sql_file_path}")
